package arxivtests;

import static org.junit.Assert.*;

import arxiv.KeywordData;
import arxiv.SearchForm;

import org.junit.Test;
import org.junit.Before;
import org.junit.After;

import java.awt.event.ActionEvent;
import java.net.*;


public class SearchFormTest {

    private SearchForm mySearchForm;
    private KeywordData mySearchData;

    @Before
    public void setUp() {
    	mySearchData = new KeywordData();
        mySearchForm = new SearchForm(mySearchData);
    }

    @After
    public void tearDown() {
    }

    @Test
    public void testSearchForm() {
    }

    @Test
    public void testActionPerformed() {
        fail("Not yet implemented");
        // test that Query is notified?
    }

    // testing setters and getters not necessary
    @Test
    public void testTextFields() {
    }

    @Test
    public void testEditorPane() {
        mySearchForm.setEditorPane("This is the result of the query");
        assertEquals("This is the result of the query", mySearchForm.getEditorPane());
    }

    @Test
    public void testSearchButton() {
        //mySearchForm.searchButton.doClick();
        // not sure what to assert here - how to access private variables from a unit test?
    }

    @Test
    public void testFetchUserInput() {
        boolean isQuery = mySearchForm.fetchUserInput();
        assertNotNull(mySearchData.getKeyText());
        assertNotNull(mySearchData.getAuthorText());
        assertNotNull(mySearchData.getTitleText());
        assertNotNull(mySearchData.getNumResultsText());

        assert(mySearchData.getKeyText().isEmpty());
        assert(mySearchData.getAuthorText().isEmpty());
        assert(mySearchData.getTitleText().isEmpty());
        assert(mySearchData.getNumResultsText().isEmpty());
        assertFalse(isQuery);
    }

    @Test
    public void testDisplayNoResults() {
        mySearchForm.displayNoResults();
        assertEquals("No search query entered", mySearchForm.getEditorPane());
    }

}
